Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Win32
Public Class gestTab
    Inherits System.Web.UI.Page

    'Protected WithEvents opName As System.Web.UI.HtmlControls.HtmlInputHidden
    'Protected WithEvents lkSalva As System.Web.UI.WebControls.LinkButton
    'Protected WithEvents lkAnnulla As System.Web.UI.WebControls.LinkButton
    'Protected WithEvents lkElenco As System.Web.UI.WebControls.LinkButton
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents Dataset11 As Dataset1
    Protected WithEvents da As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlSelectCommand2 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand2 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand2 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection


    Dim ParentTable As String = "Tabella"


#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Dataset11 = New Dataset1
        Me.da = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
        CType(Me.Dataset11, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'Dataset11
        '
        Me.Dataset11.DataSetName = "DataSet1"
        Me.Dataset11.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'da
        '
        Me.da.InsertCommand = Me.SqlInsertCommand1
        Me.da.SelectCommand = Me.SqlSelectCommand1
        Me.da.UpdateCommand = Me.SqlUpdateCommand1
        Me.da.DeleteCommand = Me.SqlDeleteCommand1
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO " & Session("nomeTab") & " (descrizione) VALUES (@descrizione); SELECT codice, descr" & _
               "izione FROM " & Session("nomeTab") & " WHERE (codice = @@IDENTITY)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        '        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT codice, descrizione FROM " & Session("nomeTab")
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE " & Session("nomeTab") & " SET descrizione = @descrizione WHERE (codice = @Original_codi" & _
              "ce) AND (descrizione = @Original_descrizione OR @Original_descrizione IS NULL AN" & _
              "D descrizione IS NULL); SELECT codice, descrizione FROM " & Session("nomeTab") & " WHERE (codi" & _
              "ce = @codice)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_codice", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "codice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_descrizione", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "descrizione", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@codice", System.Data.SqlDbType.SmallInt, 2, "codice"))
        '


        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = "DELETE FROM " & Session("nomeTab") & "  WHERE (Codice = @Original_Codice) AND (Descrizione = @Origi" & _
        "nal_Descrizione)"
        Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Codice", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Codice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Descrizione", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Descrizione", System.Data.DataRowVersion.Original, Nothing))

        Me.SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings("ConnString")
        CType(Me.Dataset11, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    'Protected WithEvents UcTestata1 As ucTestata


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        populateDataSet()
        If (Not Me.IsPostBack) Then
            If Not UcTestata1.carica() Then
                Response.Redirect("..\errore.htm")
            End If

        End If
        'Put user code to initialize the page here
    End Sub
    Private Sub populateDataSet()

        da.Fill(Dataset11, ParentTable)


    End Sub

    Private Sub lkSalva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkSalva.Click
        Try

            'Call update on the adapter to commit the changes, catch any exceptions that may be raised.
            da.Update(Dataset11.Tables(ParentTable))

        Catch
            Dataset11.RejectChanges()
        End Try
    End Sub

    Private Sub lkAnnulla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkAnnulla.Click
        Dataset11.RejectChanges()
    End Sub

    Private Sub lkElenco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkElenco.Click
        Response.Redirect("elencoG.aspx")
    End Sub

    
End Class
